package org.iteam.bank.signed.service;

import java.util.ArrayList;
import java.util.List;

public class ZDSQL {
	/**
	 * 拼装正大SQL <br/>
	 * 包含如下字段<br/>
	 * id,createBy,createTime,deleteTime,isDeleted,updateBy,updateTime,version <br/>
	 * 自动拼接到 参数columnNames 前面
	 * 
	 * @param tableName
	 * @param columnNames
	 * @param valuePlaceholders
	 * @return
	 */
	public static String sql(String tableName, String columnNames, String valuePlaceholders) {
		return new StringBuffer("insert into ").append(tableName).append("  ( id,createBy,createTime,deleteTime,isDeleted,updateBy,updateTime,version,")
				.append(columnNames).append(" ) values (?,?,?,?,?,?,?,?, ").append(valuePlaceholders).append(" )").toString();
	}

	/**
	 * 拼装正大SQL <br/>
	 * 包含如下字段<br/>
	 * id,createBy,createTime,deleteTime,isDeleted,updateBy,updateTime,version <br/>
	 * 自动拼接到 参数columnNames 前面
	 * 
	 * @param tableName
	 * @param columnNames
	 * @return
	 */
	public static String sql(String tableName, String columnNames) {
		String[] s = columnNames.split(",");
		StringBuffer sql = new StringBuffer();
		for (int i = 0; i < s.length; i++) {
			sql.append("?,");
		}
		if (sql.length() > 0) {
			sql.deleteCharAt(sql.length() - 1);
		}
		return sql(tableName, columnNames, sql.toString());
	}

	public static List<Object> initParams(String id, String createTime) {
		return initParams(id, "weixin", createTime);
	}

	public static List<Object> initParams(String id, String createBy, String createTime) {
		return initParams(id, createBy, createTime, null, 0, null, createTime, 0);
	}

	public static List<Object> initParams(String id, String createBy, String createTime, String deleteTime, int isDeleted, String updateBy, String updateTime,
			int version) {
		List<Object> params = new ArrayList<Object>();
		params.add(id);
		params.add(createBy);
		params.add(createTime);
		params.add(deleteTime);
		params.add(isDeleted);
		params.add(updateBy);
		params.add(updateTime);
		params.add(version);
		return params;
	}

	public static void main(String[] args) {
		System.out.println(sql("p2p_user_log", "content,type,p2p_user_id"));
	}
}
